package com.study.config;

import com.study.filter.RequestFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;

/**
 * @author hupengming
 * @Title: 过滤器配置类
 * @Description:
 * @date 2021/3/18 11:21
 */
@Configuration
public class FilterConfig {

    @Autowired
    RequestFilter requestFilter;

    @Bean
    public FilterRegistrationBean registration(){
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(requestFilter);
        registration.setUrlPatterns(Collections.singletonList("/login/**")); // 过滤器过滤的路径
        registration.setName("RequestFilter");
        registration.setOrder(1); //设置过滤器执行顺序
        return registration;
    }

}
